
import {h, onMounted} from "vue";

type Options ={
    el:string
}

export default function(options:Options):Promise<{baseUrl:string}>{
    return new Promise((resolve)=>{
        onMounted(()=>{
            let img = document.querySelector(options.el) as HTMLImageElement;
            console.log(img,"=======")
            img.onload = ()=>{

                resolve({
                    baseUrl:base64(img)
                })
            }
        })
        const base64 = (el:HTMLImageElement)=>{
            const canvasElement = document.createElement("canvas");
            const context = canvasElement.getContext('2d');
            //设置宽高
            canvasElement.width = el.width;
            canvasElement.height = el.height;
            //设置位置
            context?.drawImage(el,0,0,canvasElement.width,canvasElement.height)
            return canvasElement.toDataURL('image/svg')

        }
    })

}
